﻿/// <reference path="../../../EditedVersion/SinglePageApp/libs/protoClass.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/scripts/TripDetails.js" />

describe("Trip details", function () {
    describe("User", function () {
        var fname = "Georgi";
        var lname = "Plamenov";
        var email = "gplamenov@gmail.com";
        var phone = "0888392239";
        var age = 26;
        var gender = "Male";
        var userFullInfo;
        var userPartialInfo;

        beforeEach(function () {
            userFullInfo = new TripDetails.User(fname, lname, email, phone, age, gender);
            userPartialInfo = new TripDetails.User(fname, lname, email, phone, undefined, gender)
        });

        it("constructor sets up values correctly", function () {
            expect(userFullInfo.fname).toBe(fname);
            expect(userFullInfo.lname).toBe(lname);
            expect(userFullInfo.email).toBe(email);
            expect(userFullInfo.phone).toBe(phone);
            expect(userFullInfo.age).toBe(age);
            expect(userFullInfo.gender).toBe(gender);
        })

        it("toString() returns proper full result", function () {
            var expected = 'Име : ' + fname + ' ' + lname + '\n\t' +
                'E-mail: ' + email + '\n\t' +
                'Телефон: ' + phone + '\n' +
                'Възраст: ' + age + '\n' +
                'Пол: ' + gender;
            var actual = userFullInfo.toString();
            expect(actual).toBe(expected);
        })

        it("toString() returns proper partial result", function () {
            var expected = 'Име : ' + fname + ' ' + lname + '\n\t' +
                'E-mail: ' + email + '\n\t' +
                'Телефон: ' + phone + '\n' +
                'Пол: ' + gender;
            var actual = userPartialInfo.toString();
            expect(actual).toBe(expected);
        })
    });

    describe("Vehicle", function () {
        var carType = 'Автомобил';
        var carBrand = 'Bmw';
        var carYear = 1999;
        var carSeats = 4;
        var carConsumption = 9;
        var vehicleFullInfo;
        var vehiclePartialInfo;

        beforeEach(function () {
            vehicleFullInfo = new TripDetails.Vehicle(carType, carBrand, carYear, carSeats, carConsumption);
            vehiclePartialInfo = new TripDetails.Vehicle(carType, carBrand, undefined, 4, undefined);
        });

        it("constructor sets up values correctly", function () {
            expect(vehicleFullInfo.type).toBe(carType);
            expect(vehicleFullInfo.brand).toBe(carBrand);
            expect(vehicleFullInfo.year).toBe(carYear);
            expect(vehicleFullInfo.seats).toBe(carSeats);
            expect(vehicleFullInfo.fuelConsumption).toBe(carConsumption);
        })

        it("toString() returns proper full result", function () {
            var expected = '\n\t' + 'Тип: ' + carType +
                '\n\t' + 'Модел: ' + carBrand +
                '\n\t' + 'Година на производство: ' + carYear +
                '\n\t' + 'Свободни места: ' + carSeats +
                '\n\t' + 'Разход на гориво(л/100км): ' + carConsumption;
            var actual = vehicleFullInfo.toString();
            expect(actual).toBe(expected);
        })

        it("toString() returns proper partial result", function () {
            var expected = '\n\t' + 'Тип: ' + carType +
                '\n\t' + 'Модел: ' + carBrand +
                '\n\t' + 'Свободни места: ' + carSeats;
            var actual = vehiclePartialInfo.toString();
            expect(actual).toBe(expected);
        })
    });

    describe("Driver", function () {
        var carType = 'Автомобил';
        var carBrand = 'Bmw';
        var carYear = 1999;
        var carSeats = 4;
        var carConsumption = 9;
        var fname = "Georgi";
        var lname = "Plamenov";
        var email = "gplamenov@gmail.com";
        var phone = "0888392239";
        var age = 26;
        var gender = "Male";
        var requirements = undefined;
        var rating = undefined;
        var vehicle;
        var driver;

        beforeEach(function () {
            vehicle = new TripDetails.Vehicle(carType, carBrand, carYear, carSeats, carConsumption);
            driver = new TripDetails.Driver(fname, lname, email, phone, age, gender, vehicle, rating, requirements);
        });

        it("constructor sets up values correctly", function () {
            expect(driver.fname).toBe(fname);
            expect(driver.lname).toBe(lname);
            expect(driver.email).toBe(email);
            expect(driver.phone).toBe(phone);
            expect(driver.age).toBe(age);
            expect(driver.gender).toBe(gender);
            expect(driver.vehicle.type).toBe(carType);
            expect(driver.vehicle.brand).toBe(carBrand);
            expect(driver.vehicle.year).toBe(carYear);
            expect(driver.vehicle.seats).toBe(carSeats);
            expect(driver.vehicle.fuelConsumption).toBe(carConsumption);
        });

        it("toString() returns proper result", function () {
            var expected = 'Име : ' + fname + ' ' + lname + '\n\t' +
                'E-mail: ' + email + '\n\t' +
                'Телефон: ' + phone + '\n' +
                'Възраст: ' + age + '\n' +
                'Пол: ' + gender +
                '\n' + 'Превозно средство: ' + vehicle.toString();
            var actual = driver.toString();
            expect(actual).toBe(expected);
        });
    });

    describe("Trip", function () {
        var tripFrom = 'София';
        var tripTo = 'Варна';
        var tripDateOfDeparture = "16/09/2010";
        var trip;

        beforeEach(function () {
            trip = new TripDetails.Trip(tripFrom, tripTo, tripDateOfDeparture);
        });

        it("constructor sets value correctly", function () {
            expect(trip.from).toBe(tripFrom);
            expect(trip.to).toBe(tripTo);
            expect(trip.dateOfDeparture).toBe(tripDateOfDeparture);
        });

        it("toString() returns proper result", function () {
            var expected = 'От: ' + tripFrom +
                '\n' + 'До: ' + tripTo +
                '\n' + 'Дата и час: ' + tripDateOfDeparture;
            var actual = trip.toString();
            expect(actual).toBe(expected);
        });
    });

    describe("Price", function () {
        var value = 10;
        var bgn = 'lv.';
        var dollars = '$';
        var priceInDollars, priceInBgn;

        beforeEach(function () {
            priceInDollars = new TripDetails.Price(value, dollars);
            priceInBgn = new TripDetails.Price(value, bgn);
        });

        it("constructor sets value correctly", function () {
            expect(priceInBgn.value).toBe(value);
            expect(priceInBgn.currency).toBe(bgn);
        });

        it("toString() returns proper result in bgn", function () {
            var expected = value + bgn;
            var actual = priceInBgn.toString();
            expect(actual).toBe(expected);
        });

        it("toString() returns proper result in dollars", function () {
            var expected = dollars + value;
            var actual = priceInDollars.toString();
            expect(actual).toBe(expected);
        });
    });

    describe("Offer", function () {
        var carType = 'Автомобил';
        var carBrand = 'Bmw';
        var carYear = 1999;
        var carSeats = 4;
        var carConsumption = 9;
        var fname = "Georgi";
        var lname = "Plamenov";
        var email = "gplamenov@gmail.com";
        var phone = "0888392239";
        var age = 26;
        var gender = "Male";
        var requirements = undefined;
        var rating = undefined;
        var tripFrom = 'София';
        var tripTo = 'Варна';
        var tripDateOfDeparture = "16/09/2010";
        var value = 10;
        var bgn = 'lv.';
        var price, trip, vehicle, driver, offer;

        beforeEach(function () {
            vehicle = new TripDetails.Vehicle(carType, carBrand, carYear, carSeats, carConsumption);
            driver = new TripDetails.Driver(fname, lname, email, phone, age, gender, vehicle, rating, requirements);
            price = new TripDetails.Price(value, bgn);
            trip = new TripDetails.Trip(tripFrom, tripTo, tripDateOfDeparture);
            offer = new TripDetails.Offer(driver, price, trip);
        });

        it("constructor sets value correctly", function () {
            expect(driver.fname).toBe(fname);
            expect(driver.lname).toBe(lname);
            expect(driver.email).toBe(email);
            expect(driver.phone).toBe(phone);
            expect(driver.age).toBe(age);
            expect(driver.gender).toBe(gender);
            expect(driver.vehicle.type).toBe(carType);
            expect(driver.vehicle.brand).toBe(carBrand);
            expect(driver.vehicle.year).toBe(carYear);
            expect(driver.vehicle.seats).toBe(carSeats);
            expect(driver.vehicle.fuelConsumption).toBe(carConsumption);
            expect(price.value).toBe(value);
            expect(price.currency).toBe(bgn);
            expect(trip.from).toBe(tripFrom);
            expect(trip.to).toBe(tripTo);
            expect(trip.dateOfDeparture).toBe(tripDateOfDeparture);
        });

        it("toString() returns proper result in bgn", function () {
            var expected = driver.toString() + price.toString() + trip.toString();
            var actual = offer.toString();
            expect(actual).toBe(expected);
        });
    });
});